﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true"
    CodeBehind="Admin_User.aspx.cs" Inherits="Xiaov.SmartWeb.Application.SysAdmin.Admin_User" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="stylesheet" type="text/css" href="../Resources/xiaovcn/css/ssec-form.css" />
    <script type="text/javascript" src="../Resources/xiaovcn/scripts/common.js"></script>
    <script type="text/javascript" src="/Resources/xiaovcn/scripts/usercheck.js"></script>
    <script type="text/javascript">

        function callback(res) {
            if (res.value) {
                $.messager.alert('提示', '操作成功！');
            }
            else {
                $.messager.alert(res.error);
            }
        }



        function save() {
            var a = $('#t1').val();
            var b = $('#t2').val();
            var c = $('#t3').val();
            var d = $('#t4').val();
            var e = $('#t5').attr("checked");
            var f = $('#t6').attr("checked");
            var g = $('#t7').val();
            var roles = $('#roleselect').combogrid('getValues');
            var dept = $('#userdept').combogrid('getValue');
            Xiaov.SmartWeb.Application.SysAdmin.Admin_User.SaveUser(a, b, c, d, e, f, g, roles, dept, callback);
            clearForm();
            rebindgrid();
        }

        function del(user) {
            Xiaov.SmartWeb.Application.SysAdmin.Admin_User.DeleteUser(user.USERID, callback);
            rebindgrid();
        }

        function rebindgrid() {
            //$('#tt').datagrid('reload');
            bindgrid();
            $('#add').window('close');
        }

        function bindcombogrid() {
            $('#roleselect').combogrid({
                multiple: true,
                panelWidth: 400,
                idField: 'ROLEID',
                textField: 'ROLENAME',
                url: 'Json/Role.aspx',
                columns: [[
				        { field: 'ck', checkbox: true },
				        { field: 'ROLEID', title: '角色编码', width: 80 },
				        { field: 'ROLENAME', title: '角色名称', width: 100, formatter: function (val, rec) { return unescape(val) } },
				        { field: 'DISABLED', title: '禁用', width: 70, align: 'center' },
				        { field: 'ROLECOMMENT', title: '备注', width: 150, align: 'left', formatter: function (val, rec) { return unescape(val) } }
                    ]],
                fitColumns: true
            });
            $('#userdept').combotree({ url: 'Json/Dept.aspx?t=combotree' });
        }

        function bindgrid() {
            $('#tt').datagrid({
                title: '用户列表',
                url: 'Json/User.aspx',
                iconCls: 'icon-applicationgo',
                nowrap: true,
                rownumbers: true,
                animate: false,
                collapsible: false,
                singleSelect: true,
                remoteSort: false,
                columns: [[
                             { field: 'USERNAME', title: '姓名', width: 100, sortable: true, formatter: function (val, rec) { return unescape(val) } },
                             { field: 'LOGINNAME', title: '登录名', sortable: true, width: 100, formatter: function (val, rec) { return unescape(val) } },
                             { field: 'PASSWORD', title: '密码', width: 100, formatter: function (val, rec) { return unescape(val) } },
                             { field: 'DISABLED', title: '禁用', width: 30, formatter: function (val, rec) { return unescape(val) } },
                             { field: 'SUPERADMIN', title: '超管', width: 30, formatter: function (val, rec) { return unescape(val) } },
                             { field: 'USERSORT', title: '排序', sortable: true, width: 30, formatter: function (val, rec) { return unescape(val) } },
                             {
                                 field: 'USERID', title: '角色', width: 300, formatter: function (value) {
                                     return getRoleDescript(value);
                                 }
                             }
                    ]],
                toolbar: [{
                    text: '增加用户',
                    iconCls: 'icon-add',
                    handler: function () {
                        //增加用户
                        clearForm();
                        $('#add').window('open');

                    }
                }, '-', {
                    text: '编辑用户',
                    iconCls: 'icon-edit',
                    handler: function () {
                        editrow();
                    }
                }, '-', {
                    text: '删除用户',
                    iconCls: 'icon-cancel',
                    handler: function () {
                        //删除用户
                        var user = $('#tt').datagrid('getSelected');
                        if (user) {
                            $.messager.confirm('提示', '确定要删除【' + unescape(user.USERNAME) + '】这个用户吗?', function (r) {
                                if (r) {
                                    del(user);
                                }
                            });
                        }
                    }
                }],
                onLoadSuccess: function () {
                    $('#mask').fadeOut();
                },
                onDblClickRow: function () {
                    editrow();
                }
            });
        }

        function editrow() {
            //编辑用户
            var user = $('#tt').datagrid('getSelected');
            if (user) {
                $('#add').window('open');
                $('#t1').attr('value', user.USERID);
                $('#t2').attr('value', user.USERNAME);
                $('#t3').attr('value', user.LOGINNAME);
                if (user.DISABLED == "1")
                    $('#t5').attr('checked', true);
                else
                    $('#t5').attr('checked', false);
                if (user.SUPERADMIN == "1")
                    $('#t6').attr('checked', true);
                else
                    $('#t6').attr('checked', false);
                $('#t7').attr('value', user.USERSORT);
                //combo tree grid
                $('#roleselect').combogrid('clear');
                var sv = Xiaov.SmartWeb.Application.SysAdmin.Admin_User.GetRolesIdByUserId(user.USERID).value;
                //$('#roleselect').combogrid('setValues', Xiaov.SmartWeb.Application.SysAdmin.Admin_User.GetRolesIdByUserId(user.USERID).value);
                $('#roleselect').combogrid('setValues', sv.split(','));

                //$('#userdept').combogrid('clear');
                $('#userdept').combotree('setValue', user.USERDEPT);
            }
            else {
                alert('请选中一个用户');
            }
        }

        $(function () {
            bindgrid();
            bindcombogrid();
        });
        function getRoleDescript(userid) {
            //同步调用
            return Xiaov.SmartWeb.Application.SysAdmin.Admin_User.GetRolesDescriptByUserId(userid).value;
        }

    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <table id="tt">
    </table>
    <script>
        $('#tt').css('height', userScreenHeight + 20);
    </script>
    <div id="add" class="easyui-window" closed="true" modal="true" title="用户信息" style="width: 400px;">
        <div id="contents" class="ssec-form">
            <table>
                <tr>
                    <td>
                        <div class="ssec-label">
                            用户ID：</div>
                    </td>
                    <td>
                        <div class="ssec-text normal">
                            <asp:TextBox ID="t1" ClientIDMode="Static" runat="server" CssClass="ssec-text-field "
                                Enabled="false"></asp:TextBox></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            姓名：</div>
                    </td>
                    <td>
                        <div class="ssec-text normal">
                            <asp:TextBox ID="t2" ClientIDMode="Static" runat="server" CssClass="ssec-text-field"></asp:TextBox></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            登陆名：</div>
                    </td>
                    <td>
                        <div class="ssec-text normal">
                            <asp:TextBox ID="t3" ClientIDMode="Static" runat="server" CssClass="ssec-text-field"></asp:TextBox></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            密码：</div>
                    </td>
                    <td>
                        <div class="ssec-text normal">
                            <asp:TextBox ID="t4" ClientIDMode="Static" runat="server" CssClass="ssec-text-field"
                                TextMode="Password"></asp:TextBox></div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            禁用：</div>
                    </td>
                    <td>
                        <asp:CheckBox ID="t5" ClientIDMode="Static" runat="server"></asp:CheckBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            超管：</div>
                    </td>
                    <td>
                        <asp:CheckBox ID="t6" ClientIDMode="Static" runat="server"></asp:CheckBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            角色：</div>
                    </td>
                    <td>
                        <%-- <asp:DropDownList ID="roleselect" runat="server" ClientIDMode="Static" CssClass="easyui-combogrid"
                            Width="200px" >
                        </asp:DropDownList>--%>
                        <input id="roleselect" class="easyui-combogrid" style="width: 230px" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            所属机构：</div>
                    </td>
                    <td>
                        <input class="easyui-combotree" ID="userdept" style="width: 230px" />
                       <%-- <asp:TextBox ID="userdept" runat="server" ClientIDMode="Static" Width="280px"></asp:TextBox>--%>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="ssec-label">
                            排序：</div>
                    </td>
                    <td>
                        <div class="ssec-text normal">
                            <asp:TextBox ID="t7" ClientIDMode="Static" runat="server" CssClass="ssec-text-field easyui-numberbox"></asp:TextBox></div>
                    </td>
                </tr>
            </table>
            <div>
                <a class="easyui-linkbutton" onclick="save();" iconcls="icon-save">保存</a></div>
        </div>
    </div>
</asp:Content>
